#include "sComponentResource.h"

#include "sComponentButton.h"
#include "sComponentCheckbox.h"

namespace sgui
{

DEFINE_FABRIC(fbComponentButton, 
	new res::sComponentButton(gui, *file.getName())
);
DEFINE_FABRIC(fbComponentCheckbox, 
	new res::sComponentCheckbox(gui, *file.getName())
);

// ----------------------------------- fbResource: fabric -------------------------------------
DEFINE_FABRIC_BEGIN(fbComponent)

	const std::wstring &name = file.GetAsString();

	std::map<std::wstring, const sNamedObjectFabric*>	m_fabrics;

	m_fabrics.insert(std::pair<std::wstring, const sNamedObjectFabric*>(
		res::sComponentButton::COMPONENT_NAME, &fbComponentButton
	));
	m_fabrics.insert(std::pair<std::wstring, const sNamedObjectFabric*>(
		res::sComponentCheckbox::COMPONENT_NAME, &fbComponentCheckbox
	));

	std::map<std::wstring, const sNamedObjectFabric*>::const_iterator ps = m_fabrics.find(name);

	if (ps != m_fabrics.end())
	{
		return ps->second->CreateObject(gui, file);
	}

    return NULL;

DEFINE_FABRIC_END(fbComponent);
// -----------------------------------------------------------------------------------------

namespace res
{

const std::wstring sComponentResource::RESOURCE_NAME = L"CMP";

CONTAINER_WRAPPER(sComponent)& sComponentResource::getComponents()
{
	return m_components;
}

const CONTAINER_WRAPPER(sComponent)& sComponentResource::getComponents() const
{
	return m_components;
}

#ifdef _EDITOR
void sComponentResource::exportRTTI(rtti::sInfoList& list)
{
    sResource::exportRTTI(list);
}
#endif

void sComponentResource::load(const db::Record &file)
{
	sResource::load(file);
	m_components.load(file[L"components"], fabric::fbComponent);
}

void sComponentResource::save(db::Record &file) const
{
	sResource::save(file);
	m_components.save(file[L"components"]);
}

void sComponentResource::clear()
{
    sResource::clear();
	m_components.clear();
}
        
preset::sPreset* sComponentResource::getPreset(const std::wstring& name)
{
    return NULL;
}

sComponentResource::sComponentResource(sGUI&gui, const std::wstring& name) :
    sResource(gui, name),
	m_components(gui)
{
    //
}

sComponentResource::~sComponentResource()
{
    //
}

};
};